﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TagLib;

namespace Mp3Tagger
{
	public partial class Form1 : Form
	{
		TagLib.File f = null;
		public Form1()
		{
			InitializeComponent();
		}

		private Tag ReadMp3ID3(string path)
		{
			 
			try
			{
			f = TagLib.File.Create(path);
			return f.GetTag(TagTypes.Id3v2);
			//Picture picture = new Picture(picPath);

			//f.Tag.Pictures = new IPicture[] { picture };
			}
			catch (Exception ex)
			{ MessageBox.Show(ex.Message); return null; }


		}

		private void button1_Click(object sender, EventArgs e)
		{

			var tag = ReadMp3ID3(@"D:\tmp\06. Vampiria.mp3");
			richTextBox1.AppendText(string.Format("{0} - {1} - {2}", tag.Artists[0], tag.Album, tag.Title));
		}

		private void button2_Click(object sender, EventArgs e)
		{
			if (f == null) return;
			if (f.Tag.Pictures.Length > 0)
				f.Tag.Pictures = null;
			var picture = new Picture(@"D:\tmp\img\Cover-moonspell_wolfheart_cover.jpg");
			picture.Type = PictureType.FrontCover;
			picture.Description = "";
			f.Tag.Pictures = new IPicture[] { picture };
			f.Save();
		}


	}
}
